package com.zhongnan.Demo3_Date;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateDemo {
    public static void main(String[] args) {


        String xiaopi = "2021/01/10 00:03:10";
        String xiaojia = "2021/01/10 00:10:11";

        Date xiaopi1 = simpleDate(xiaopi);
        Date xiaojia1 = simpleDate(xiaojia);
        hikaku(xiaopi1, "xiaopi");
        hikaku(xiaojia1, "xiaojia");
    }

    private static void hikaku(Date date, String name) {
        String start = "2021/01/10 00:00:00";
        String end = "2021/01/10 00:10:00";
        Date start1 = simpleDate(start);
        Date end1 = simpleDate(end);
        if (date.getTime() >= start1.getTime() && end1.getTime() >= date.getTime()) {
            System.out.println(name + "买到了");
        } else{
            System.out.println(name + "没买到");
        }
    }

    private static Date simpleDate(String date) {
        SimpleDateFormat spf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        Date date1 = null;
        try {
            date1 = spf.parse(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date1;
    }
}
